package com.xlhj.boot.mockmvc.controller;

import com.xlhj.boot.mockmvc.dto.MockMvcDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: liucaijing
 * @description: MockMvcController
 * @date: 2022/3/31 10:27
 */
@RestController
@RequestMapping("/mockmvc")
public class MockMvcController {

    @GetMapping("/getInfo")
    public String getInfo() {
        return "hello mockmvc!";
    }

    @GetMapping("/getInfoById/{id}")
    public String getInfoById(@PathVariable Long id) {
        return "hello mockmvc:" + id;
    }

    @GetMapping("/getInfoByName")
    public String getInfoByName(@RequestParam String name) {
        return "hello mockmvc:" + name;
    }

    @PostMapping("/saveInfo")
    public String saveInfo(@RequestHeader(value = "header") String header,
                           @RequestParam String country, @RequestBody MockMvcDto mockMvcDto) {
        return "hello mockmvc:" + header + "-" + country + "-" + mockMvcDto.toString();
    }
}
